package com.zjut.azhen.DBDesign.component;

import com.zjut.azhen.DBDesign.bean.User;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author asus
 */
@Component
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object user=request.getSession().getAttribute("user");
        //User user =(User)session.getAttribute("user");
        System.out.println(user);
        if(user==null){
            //未登录,发送未登录消息
            request.getRequestDispatcher("/auth/unlogin").forward(request,response);
            return false;
        }
        return true;
    }

}
